<template>
    <div>
        <div style="margin-top: 1%">
            <el-breadcrumb separator="/">
                <el-breadcrumb-item >首页</el-breadcrumb-item>
                <el-breadcrumb-item>采购入库</el-breadcrumb-item>
                <el-breadcrumb-item>新增</el-breadcrumb-item>
            </el-breadcrumb>
        </div>
        <el-form :model="form" :rules="rules" ref="ruleform" label-width="140px">
          <el-row>
            <el-col :span="12">
              <el-form-item label="单据编号" prop="djbh">
                <el-input v-model="form.djbh"type="number" autocomplete="off"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="供应商"  prop="gys">
                <el-input  v-model="form.gys" autocomplete="off"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="12">
              <el-form-item label="物料代码"  prop="wlzdm">
                <el-input  v-model="form.wlzdm"type="number" autocomplete="off"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="规格型号"  prop="ggxh">
                <el-input  v-model="form.ggxh" autocomplete="off"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
            <el-row>
                <el-col :span="12">
                    <el-form-item label="部门"  prop="bumen">
                        <el-input v-model="form.bumen" autocomplete="off"></el-input>
                    </el-form-item>
                </el-col>
                <el-col :span="12">
                    <el-form-item label="单价"  prop="danjia" >
                        <el-input v-model="form.danjia" type="number"autocomplete="off"></el-input>
                    </el-form-item>
                </el-col>
            </el-row>

            <el-row>
                <el-col :span="12">
                    <el-form-item label="数量"  prop="shuliang">
                        <el-input type="number" v-model="form.shuliang" autocomplete="off"></el-input>
                    </el-form-item>
                </el-col>   <el-col :span="12">
                    <el-form-item label="采购日期"  prop="cgriqi">
                      <el-date-picker
                        v-model="form.cgriqi"
                        type="datetime"
                        format="yyyy-MM-dd HH:mm:ss"
                        value-format="yyyy-MM-dd HH:mm:ss"
                        default-time="12:00:00"
                        placeholder="选择日期时间">
                      </el-date-picker>
                    </el-form-item>
                </el-col>
            </el-row>
            <el-row>
                <el-col :span="12">
                    <el-form-item label="收料仓库"  prop="slck">
                        <el-input  v-model="form.slck" autocomplete="off"></el-input>
                    </el-form-item>
                </el-col>
                <el-col :span="12">
                    <el-form-item label="物料名称"  prop="wlmc">
                        <el-input  v-model="form.wlmc" autocomplete="off"></el-input>
                    </el-form-item>
                </el-col>
            </el-row>
          <el-row>
            <el-col :span="12">
              <el-form-item label="金额"  >
                <el-input v-model="jiner" :readonly="true" type="number"placeholder="自动计算"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="制单人"  prop="zdr">
                <el-input v-model="form.zdr" autocomplete="off"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
        </el-form>
        <div slot="footer" class="dialog-footer">
            <el-button @click="resetForm">重 置</el-button>
            <el-button type="primary" @click="handleConfine">确 定</el-button>
        </div>
    </div>
</template>

<script>
import CgrkApi from "../../../api/CgrkApi";
  export default {
    name: 'index',
    data(){
      return{
        form: {
          djbh: '',//单据编号
          gys: '',//供应商
          wlzdm: '',//物料代码
          wlmc: '',//物料名称
          ggxh: '',//规格型号
          bumen: '',//部门
          danjia: '',//单价
          shuliang: '',//数量
          slck: '',//收料仓库
          jiner: '',//金额
          zdr: '',//制单人
          cgriqi: '',//采购日期
        },
        labelWidth:'100px',
        rules: {
          bumen: [
            { required: true, message: '部门', trigger: 'blur' },
          ],
          danjia: [
            { required: true, message: '单价', trigger: 'blur' },
          ],
          djbh: [
            { required: true, message: '单据编号', trigger: 'blur' },
          ],
          danwei: [
            { required: true, message: '单位', trigger: 'blur' },
          ],
          fktj: [
            { required: true, message: '付款条件', trigger: 'blur' },
          ],gys: [
            { required: true, message: '供应商', trigger: 'blur' },
          ],wlzdm: [
            { required: true, message: '物料长代码', trigger: 'blur' },
          ],ggxh: [
            { required: true, message: '规格型号', trigger: 'blur' },
          ],jiner: [
            { required: true, message: '金额', trigger: 'blur' },
          ],cgriqi: [
            { required: true, message: '日期', trigger: 'blur' },
          ],shbz: [
            { required: true, message: '审核标志', trigger: 'blur' },
          ],shuliang: [
            { required: true, message: '实收数量', trigger: 'blur' },
          ],slck: [
            { required: true, message: '收料仓库', trigger: 'blur' },
          ],wlmc: [
            { required: true, message: '物料名称', trigger: 'blur' },
          ],zdr: [
            { required: true, message: '制单人', trigger: 'blur' },
          ],
        }
      }
    },
    computed:{
      jiner(){
      return this.form.danjia*this.form.shuliang
      }

    },
    watch:{
      jiner(val) {
        this.form.jiner = val;
      },
    },
    methods:{
      //确认添加
      handleConfine() {
        var validate = false;
        this.$refs['ruleform'].validate((valid) => {
          if (valid) {
            validate = true;
          } else {
            console.log('error submit!!');
            validate = false;
            return false;
          }
        });
        if (validate === false) {
          return;
        }
        let data = {
          djbh:this.form.djbh,//单据编号
          gys: this.form.gys,//供应商
          wlzdm: this.form.wlzdm,//物料代码
          wlmc: this.form.wlmc,//物料名称
          ggxh: this.form.ggxh,//规格型号
          bumen: this.form.bumen,//部门
          danjia: this.form.danjia,//单价
          shuliang: this.form.shuliang,//数量
          slck:this.form.slck,//收料仓库
          jiner: this.form.jiner,//金额
          zdr: this.form.zdr,//制单人
          cgriqi: this.form.cgriqi,//制单人
        }

        CgrkApi.add(data)
          .then(res => {
            // 返回数据
            if(res.flag){
              this.$message.success("添加成功!");
              this.form  = {
                djbh: '',//单据编号
                gys: '',//供应商
                wlzdm: '',//物料代码
                wlmc: '',//物料名称
                ggxh: '',//规格型号
                bumen: '',//部门
                danjia: '',//单价
                shuliang: '',//数量
                slck: '',//收料仓库
                jiner: '',//金额
                zdr: '',//制单人
              }
            }
            this.showAddDialog = false;
          })
          .catch(err => {
            // 异常情况
          })

      },
      resetForm() {
        this.$refs['ruleform'].resetFields();
      },
    }
  };
</script>

<style scoped>

</style>
